/*
岩土工程师工具箱系列软件
版本：0.20
作者：Jack Hsu
Email:jackhsu@95ie.com
官方网站：http://www.95ie.com
更新日期：8:33 2010-10-29
file name:designfee.js
*/
//define css strings
var getbcssstring="<style type=\'text\/css\'>";
	getbcssstring+="#getoolbox{width:186px;font-family:Georgia,微软雅黑;font-size:12px;background:#B9E2FF;padding:5px 1px;}";
	getbcssstring+="#getoolbox a:link, a:active,a:visited{color:#0079b7; text-decoration:none}";
	getbcssstring+="#GEDFCalBox table{margin:8px 0px 0px 5px;}";
	getbcssstring+="#GeoEngDesFee{width:55px;float:right;}";
	getbcssstring+=".getbInputText{width:38px;}";
	getbcssstring+=".getbResult{overflow:hidden;}";
	getbcssstring+=".tooltitle,#copyright {text-align:center;clear:both;}";
	getbcssstring+="<\/style>";
document.writeln(getbcssstring);
//
/*
岩土工程设计收费计算器
编制依据：《工程勘察设计收费标准》（2002年修订本）。
*/
//define getbFrame;
document.writeln("<div id=\"getoolbox\">");
document.writeln("</div>");
var getbFrame=document.getElementById("getoolbox");
//
showModuleGEDFee();

function showModuleGEDFee()
{
var strModuleGEDFee="<div id=\"GEDFCalBox\"><table>";
	strModuleGEDFee+="<caption title=\"根据《工程勘察设计收费标准》（2002年修订本）编制\">岩土工程设计收费计算器</caption>";
	strModuleGEDFee+="<tbody><tr>";
	strModuleGEDFee+="<td>工程概算：</td><td><input type=\"text\" id=\"GeoEngCost\" size=6 maxlength=10/></td><td>万元</td>";
	strModuleGEDFee+="</tr>";
	strModuleGEDFee+="<tr><td>复杂程度：</td>";
	strModuleGEDFee+="<td><select id=\"GeoEngDegree\"><option>I级</option><option>II级</option><option>III级</option></select></td></tr>";
	strModuleGEDFee+="<tr><td>设计收费：</td><td><div id=\"GeoEngDesFee\" class=\"getbResult\"></div></td><td>万元</td></tr>";
	strModuleGEDFee+="<tr><td>r45</td><td><input type=\"button\" value=\"计算\" onclick=\"getgedfee()\" /></td><td></td></tr>";
	strModuleGEDFee+="</tbody></table>";
	if (location.hostname=="95ie.com"||location.hostname=="www.95ie.com")
	{
		strModuleGEDFee+="</div>";
		document.getElementById("getoolbox").style.height="140";
	}
	else
	{
		strModuleGEDFee+="<div id=\"copyright\">Powered by <a href=\"http://95ie.com\" target=\"_blank\">95ie.com</a></div></div>";
		document.getElementById("getoolbox").style.height="150";
	}
	getbFrame.innerHTML="";
	getbFrame.innerHTML=strModuleGEDFee;
}
//show gedfee end

function getgedfee()
{
var gectxt=document.getElementById("GeoEngCost");
var gede=document.getElementById("GeoEngDegree");
var gef=document.getElementById("GeoEngDesFee");
var geco=gectxt.value;
var gedeg=gede.selectedIndex+1;
var gedfeeresult=gedfee(geco,gedeg);
	gef.innerHTML=myround3(gedfeeresult);
//输出计算结果
	document.getElementById("GeoEngCostOutput").innerHTML=geco;
	switch(gedeg)
		{
		case 1:
		document.getElementById("GeoEngDegreeOutput").innerHTML="I级";
		break
		case 2:
		document.getElementById("GeoEngDegreeOutput").innerHTML="II级";
		break
		case 3:
		document.getElementById("GeoEngDegreeOutput").innerHTML="III级";
		break
		}
	document.getElementById("GeoEngDesFeeOutput").innerHTML=gef.innerHTML;
	document.getElementById("GeoEngDesFeeOutput2").innerHTML=gef.innerHTML;	
}
//gedfee，插值计算设计费
function gedfee(cost,degree)
{
var arrcost=new Array(0,10,50,100,500,1000,2000);
var arrfeeone=new Array(0,0.64,2.8,5.4,23,43,78);
var arrfeetwo=new Array(0,0.75,3.3,6.3,27,50,92);
var arrfeethree=new Array(0,0.86,3.8,7.2,31,58,106);
var gfee=0;
	if(cost>0 && cost<=2000)
	{
		switch(degree)
		{
		case 1:
			for(i=0;i<=5;i++)
			{
				if(cost>arrcost[i] && cost<=arrcost[i+1])
				{
				gfee=(arrfeeone[i+1]-arrfeeone[i])/(arrcost[i+1]-arrcost[i])*(cost-arrcost[i])+arrfeeone[i];
				}
			}
		break
		case 2:
			for(i=0;i<=5;i++)
			{
				if(cost>arrcost[i] && cost<=arrcost[i+1])
				{
				gfee=(arrfeetwo[i+1]-arrfeetwo[i])/(arrcost[i+1]-arrcost[i])*(cost-arrcost[i])+arrfeetwo[i];
				}
			}
		break
		case 3:
			for(i=0;i<=5;i++)
			{
				if(cost>arrcost[i] && cost<=arrcost[i+1])
				{
				gfee=(arrfeethree[i+1]-arrfeethree[i])/(arrcost[i+1]-arrcost[i])*(cost-arrcost[i])+arrfeethree[i];
				}
			}
		break
		}
		gfee=(gfee<0.5)? 0.5 : gfee;
	}
	else if(cost<=0)
	{
		gfee="<span>error</span>";
	}
	else{
		switch(degree)
		{
		case 1:
		gfee=cost*0.035;
		break
		case 2:
		gfee=cost*0.045;
		break
		case 3:
		gfee=cost*0.05;
		break
		}
	}
	return gfee;
}
//gedfee，插值计算设计费
/*
通用函数myround，对输入数据四舍五入，取3位小数。
*/
function myround3(thestring)
{
var pat=new RegExp("[0-9]*\.[0-9]{0,3}");
return pat.exec(thestring);
}